package com.aokser.redisplugin.api;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.aokser.redisplugin.config.BaseConfig;
import com.aokser.redisplugin.exception.RedisPluginException;
import com.aokser.redisplugin.redis.AbstractRedisPluginClient;
import com.aokser.redisplugin.redis.RedisPluginClusterClient;
import com.aokser.redisplugin.redis.RedisPluginSingleClient;
import com.aokser.redisplugin.util.SpringContextUtil;

/**
 * 组件
 * @version 1.0
 * @author aokser@foxmail.com
 */
@Component
public class RedisPlugin {
	
	@Autowired
    protected BaseConfig config;
    
	/**
	 * 获取Redis客户端实例
	 */
    public AbstractRedisPluginClient getRedisClient() {
    	AbstractRedisPluginClient client = null;
        if(config.isCluster()) {
            client = SpringContextUtil.getBean(RedisPluginClusterClient.class);
        } else {
            client = SpringContextUtil.getBean(RedisPluginSingleClient.class);
        }
        if(null == client) {
            throw new RedisPluginException("Redis客户端接口实例化异常！");
        }
        return client;
    }

}
